# Maintainer: Andrea Zagli <andrea.zagli.free@gmail.com>

_realname=liboauth
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.0.3
pkgrel=6
arch=('any')
pkgdesc="liboauth is a collection of POSIX-c functions implementing the OAuth Core RFC 5849 standard (mingw-w64)"
license=("GPL 2")
url="https://liboauth.sourceforge.io/"
depends=("${MINGW_PACKAGE_PREFIX}-curl"
         "${MINGW_PACKAGE_PREFIX}-nss"
         )
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-doxygen"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "make"
             "libtool"
             "automake-wrapper"
             "autoconf"
             "patch")
options=('strip' '!debug' 'staticlibs')
source=(https://downloads.sourceforge.net/project/${_realname}/${_realname}-${pkgver}.tar.gz
        noundefined.patch)
sha256sums=('0df60157b052f0e774ade8a8bac59d6e8d4b464058cc55f9208d72e41156811f'
            'ae77e26395eedd19e27359579ace90976e6d7746bb3fcfa56493c2b1a60f9970')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/noundefined.patch

  autoreconf -fi
}

build() {
  [[ -d build-${MINGW_CHOST} ]] && rm -rf build-${MINGW_CHOST}
  mkdir -p build-${MINGW_CHOST}
  cd build-${MINGW_CHOST}

  ../${_realname}-${pkgver}/configure \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --build=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX} \
    --libexecdir=${MINGW_PREFIX}/lib \
    --enable-nss

  make
  # make dox # Generate doxygen docs
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR=${pkgdir} install
}
